﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace skydream
{
    /// <summary>
    /// 数据连接服务
    /// </summary>
    public class DBConnection
    {
        /// <summary>
        /// 提供链接sqlServer字符串
        /// 
        /// </summary>
        /// <returns></returns>
        //public static SqlConnection getSqlServerConn(string str)
        //{
        //    //链接字符串
        //    //str = "";
        //    //str += " Data Source=" + PDAHelp.getXMLText(0) + ";" + "initial catalog=" + PDAHelp.getXMLText(3) + ";User ID =" + PDAHelp.getXMLText(1) + ";" + "password=" + PDAHelp.getXMLText(2);
        //    SqlConnection conn = null;
        //    conn = new SqlConnection(str);
        //    return conn;
        //}
        //
        // 摘要:
        //     提供链接sqlServer需要连接的字符串组（需要提供XmlFile配置文件）
        //
        // 返回结果:
        //     sqlServer链接文件
        public static SqlConnection getSqlServerConn(string xmlFileName)
        {
            
            //链接字符串
            string str= " Data Source=" +
                XmlHelp.getXmlText(xmlFileName, 0)[1] + ";" + "initial catalog=" +
                XmlHelp.getXmlText(xmlFileName, 1)[1] + ";User ID =" +
                XmlHelp.getXmlText(xmlFileName, 2)[1] + ";" + "password=" +
                XmlHelp.getXmlText(xmlFileName, 3)[1];
            SqlConnection conn = null;
            conn = new SqlConnection(str);
            return conn;
        }

    }
}
